home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / image / ind2rgb.m < prev    next >
Text File  |  1996-10-10  |  2KB  |  63 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Convert an indexed image to red, green, and blue color components.
  21. ##
  22. ## [R G B] = ind2rgb(X) uses the current colormap for the conversion.
  23. ##
  24. ## [R G B] = ind2rgb(X,map) uses the specified colormap.
  25. ##
  26. ## SEE ALSO: rgb2ind, image, imshow, ind2gray, gray2ind.
  27.  
  28. ## Author: Tony Richardson <amr@mpl.ucsd.edu>
  29. ## Created: July 1994
  30. ## Adapted-By: jwe
  31.  
  32. function [R, G, B] = ind2rgb (X, map)
  33.  
  34.   if (nargin < 1 || nargin > 2)
  35.     usage ("ind2rgb (X, map)");
  36.   elseif (nargin == 1)
  37.     map = colormap ();
  38.   endif
  39.  
  40.   [hi, wi] = size (X);
  41.  
  42.   ## XXX FIXME XXX -- we should check size of X and map.
  43.  
  44.   pref = do_fortran_indexing;
  45.  
  46.   unwind_protect
  47.  
  48.     do_fortran_indexing = 1;
  49.  
  50.     R = map (X(:), 1);
  51.     G = map (X(:), 2);
  52.     B = map (X(:), 3);
  53.  
  54.     R = reshape (R, hi, wi);
  55.     G = reshape (G, hi, wi);
  56.     B = reshape (B, hi, wi);
  57.  
  58.   unwind_protect_cleanup
  59.     do_fortran_indexing = pref;
  60.   end_unwind_protect
  61.  
  62. endfunction
  63.